<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
   //用户添加
    public function getAdd(){
        return view('admin.user.add');
    }

    public function postInsert(Request $request)
    {
        $this->validate($request,[
            'uname'=> 'required',
            'upass'=> 'required',
            'urepass'=>'required|same:upass',
            'uemail'=> 'required|email',
            ],[
                'uname.required'=>'用户名不能为空',
                'upass.required'=>'密码不能为空',
                'urepass.required'=>'确认密码不能为空',
                'urepass.same'=>'两次密码不一致',
                'uemail.required'=>'邮箱不能为空',
                'uemail.email'=>'邮箱格式不正确',

            ]);
        // $res = DB::table('user')
    }

    //浏览用户
    public function getIndex()
    {
        return view('admin.user.index');
    }

    //用户修改
    public function getEdit()
    {
        return view('admin.user.edit');
    }

    //用户删除
    public function getDel($id)
    {
        $res = DB::table('user') -> where('uid',$id) -> delete();
        //处理结果
        if($res > 0)
        {
            return redirect('/admin/user/index') -> with('success','删除成功');
        }else{
            return back() -> with('error','删除失败');
        }
    }
}
